import lodash from 'lodash'

export class SessionUtils {
    static get(key) {
        return JSON.parse(window.sessionStorage.getItem(key))
    }
    static set(key, value) {
        window.sessionStorage.setItem(key, JSON.stringify(value))
    }
    static remove(key) {
        window.sessionStorage.removeItem(key)
    }
}

export function rulesMenu(menu,dymenu){
    let deepCopyMenu = lodash.cloneDeep(menu);
    let newMenu = [];
    // 递归遍历寻找符合条件的菜单项
    deepCopyMenu.forEach((ele)=>{
        dymenu.forEach(item=>{
            if(item.name===ele.meta.title){
                if(item.children && item.children.length>0){
                    ele.children=rulesMenu(ele.children,item.children);
                }
                newMenu.push(ele);
            }
        })
    })
    return newMenu;
}